﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Configuration;
using System.Net;
using CloudReader.Runtime;

namespace CloudReader
{
    /// <summary>
    /// Login.xaml 的交互逻辑
    /// </summary>
    public partial class Login : Window
    {
        public Login()
        {
            InitializeComponent();
            CommonRuntime.Client.OnLoginSuccess += new Action(OnLoginSuccess);
            CommonRuntime.Client.OnLoginFailed += new Action(OnLoginFailed);
        }

        private void LoginButton(object sender,RoutedEventArgs e)
        {
            var ip = IPAddress.Parse(ConfigurationManager.AppSettings["server"]);
            CommonRuntime.Client.Login(ip, user.Text, pw.Password);
        }
        private void OnLoginSuccess()
        {
            Dispatcher.Invoke(() =>
            {
                MainWindow m = new MainWindow();
                m.Show();
                this.Close();
            });

        }
        private void OnLoginFailed()
        {
            Dispatcher.Invoke(() =>
            {
                pw.Password = "";
                MessageBox.Show("登陆失败，请检查密码或用户名是否正确");
            });

        }
    }
}
